unit Unit5;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Grids, DBGrids, StdCtrls, Buttons, ComCtrls, jpeg, ExtCtrls,
  DBCtrls, Mask;

type
  Tfrmoperacao = class(TForm)
    Image1: TImage;
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    Label1: TLabel;
    Label2: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label6: TLabel;
    Label5: TLabel;
    Label4: TLabel;
    Label3: TLabel;
    ed_codusuario: TEdit;
    ed_codagend: TEdit;
    GroupBox2: TGroupBox;
    ck_domingo: TCheckBox;
    ck_segunda: TCheckBox;
    ck_terca: TCheckBox;
    ck_quarta: TCheckBox;
    ck_quinta: TCheckBox;
    ck_sexta: TCheckBox;
    lb_dispagend: TListBox;
    GroupBox1: TGroupBox;
    rb_ativo: TRadioButton;
    rb_desativado: TRadioButton;
    GroupBox3: TGroupBox;
    Label12: TLabel;
    Label11: TLabel;
    GroupBox4: TGroupBox;
    rb_simples: TRadioButton;
    rb_rotina: TRadioButton;
    TabSheet2: TTabSheet;
    Label17: TLabel;
    Label18: TLabel;
    SpeedButton7: TSpeedButton;
    cb_tippesquisa: TComboBox;
    ed_pesquisa: TEdit;
    db_agendamentos: TDBGrid;
    SpeedButton3: TSpeedButton;
    SpeedButton4: TSpeedButton;
    SpeedButton5: TSpeedButton;
    SpeedButton6: TSpeedButton;
    cb_setor: TDBLookupComboBox;
    ed_hora_ini: TMaskEdit;
    ed_hora_fim: TMaskEdit;
    SpeedButton8: TSpeedButton;
    SpeedButton9: TSpeedButton;
    lb_dispsetor: TDBLookupListBox;
    sb_incluir: TSpeedButton;
    sb_salvar: TSpeedButton;
    SpeedButton1: TSpeedButton;
    sb_excluir: TSpeedButton;
    SpeedButton2: TSpeedButton;
    ed_data_ini: TEdit;
    ed_data_fim: TEdit;
    ck_sabado: TCheckBox;
    cb_op_ini: TComboBox;
    cb_op_fim: TComboBox;
    Label10: TLabel;
    procedure SpeedButton2Click(Sender: TObject);
    procedure sb_incluirClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure sb_excluirClick(Sender: TObject);
    procedure SpeedButton3Click(Sender: TObject);
    procedure SpeedButton8Click(Sender: TObject);
    procedure cb_setorExit(Sender: TObject);
    procedure SpeedButton9Click(Sender: TObject);
    procedure SpeedButton4Click(Sender: TObject);
    procedure SpeedButton5Click(Sender: TObject);
    procedure SpeedButton6Click(Sender: TObject);
    procedure cb_setorEnter(Sender: TObject);
    procedure cb_setorClick(Sender: TObject);
    procedure cb_setorDragDrop(Sender, Source: TObject; X, Y: Integer);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmoperacao: Tfrmoperacao;
  n: integer;

implementation

uses Unit1, Unit2, Unit3, Unit4, Unit6, Unit7, Unit8, Unit9;

{$R *.dfm}

procedure Tfrmoperacao.SpeedButton2Click(Sender: TObject);
begin
  frmoperacao.Close;
end;

procedure Tfrmoperacao.sb_incluirClick(Sender: TObject);
begin
   self.ed_codusuario.Clear;
   self.ed_codagend.Clear;



   dmbanco.util.SQL.Text := 'SELECT * FROM USUARIOS WHERE LOGIN=' + #39 + frmprincipal.lb_usuario.Caption + #39;
   dmbanco.util.Open;
   self.ed_codusuario.ReadOnly := false;
   self.ed_codusuario.Text := inttostr(dmbanco.util.FieldByName('id').AsInteger);
   self.ed_codusuario.ReadOnly := true;
   self.rb_ativo.Checked := true;
   self.rb_rotina.Checked := true;
   dmbanco.util.close;
   dmbanco.util.SQL.Clear;

   ed_codagend.Text := inttostr(dmbanco.tb_agenda.RecordCount + 1);

   ed_data_ini.Text := '';
   ed_data_fim.Text := '';

   ed_hora_ini.Text := '';
   ed_hora_fim.Text := '';

    cb_op_ini.Enabled := true;
    cb_op_fim.Enabled := true;

   lb_dispsetor.KeyField := '';
   lb_dispagend.Clear;

   cb_setor.Enabled := true;

   rb_ativo.Checked := true;
   rb_rotina.Checked := true;

   ck_domingo.Checked := false;
   ck_segunda.Checked := false;
   ck_terca.Checked := false;
   ck_quarta.Checked := false;
   ck_quinta.Checked := false;
   ck_sexta.Checked := false;
   ck_sabado.Checked := false;

  pagecontrol1.ActivePageIndex := 0;


end;

procedure Tfrmoperacao.FormShow(Sender: TObject);
begin
label10.Caption := inttostr(DayOfWeek(date));
if cb_setor.Text <> '' then
  begin
    dmbanco.set_dispositivos.Close;
    dmbanco.set_dispositivos.SQL.Clear;
    dmbanco.set_dispositivos.SQL.Text := 'SELECT D.ID_SETOR, D.NOME, S.ID, S.DESCRICAO FROM SETORES S INNER JOIN DISPOSITIVOS D ON D.ID_SETOR=S.ID WHERE S.DESCRICAO=' + #39 + cb_setor.Text + #39;
    dmbanco.set_dispositivos.Open;
 	end;
pagecontrol1.ActivePageIndex := 0;
end;

procedure Tfrmoperacao.sb_excluirClick(Sender: TObject);
begin
  if pagecontrol1.ActivePageIndex = 0 then
  begin
      pagecontrol1.SelectNextPage(true);
  end
  else
  begin
        { comando para desativar o agendamento }
  end;
end;

procedure Tfrmoperacao.SpeedButton3Click(Sender: TObject);
begin
{  n := 0;
  while(n < lb_dispsetor.RowCount) do begin
    self.lb_dispagend.Items.Add(lb_dispsetor.ListField[n]);
    n := n + 1;
  end;
lb_dispsetor.CleanupInstance; }
end;

procedure Tfrmoperacao.SpeedButton8Click(Sender: TObject);
begin
  frmdata.show;
end;

procedure Tfrmoperacao.cb_setorExit(Sender: TObject);
begin
  if cb_setor.Text <> '' then
  begin
    dmbanco.set_dispositivos.Close;
    dmbanco.set_dispositivos.SQL.Clear;
    dmbanco.set_dispositivos.SQL.Text := 'SELECT D.ID_SETOR, D.NOME, S.ID, S.DESCRICAO FROM SETORES S INNER JOIN DISPOSITIVOS D ON D.ID_SETOR=S.ID WHERE S.DESCRICAO=' + #39 + cb_setor.Text + #39;
    dmbanco.set_dispositivos.Open;
 	end;
end;

procedure Tfrmoperacao.SpeedButton9Click(Sender: TObject);
begin
  frmdatafim.Show;
end;

procedure Tfrmoperacao.SpeedButton4Click(Sender: TObject);
begin
  lb_dispagend.Items.Add(lb_dispsetor.SelectedItem);
end;

procedure Tfrmoperacao.SpeedButton5Click(Sender: TObject);
begin
  //lb_dispsetor.Items.add(lb_dispagend.SelectedItem);
end;

procedure Tfrmoperacao.SpeedButton6Click(Sender: TObject);
begin
{n := 0;
  while(n < lb_dispagend.Count) do begin
    self.lb_dispsetor.Add(lb_dispagend.Items[n]);
    n := n + 1;
  end;
lb_dispagend.Clear;}
end;

procedure Tfrmoperacao.cb_setorEnter(Sender: TObject);
begin
  //cb_setor.ListField := 'descricao';
  if cb_setor.Text <> '' then
  begin
    dmbanco.set_dispositivos.Close;
    dmbanco.set_dispositivos.SQL.Clear;
    dmbanco.set_dispositivos.SQL.Text := 'SELECT D.ID_SETOR, D.NOME, S.ID, S.DESCRICAO FROM SETORES S INNER JOIN DISPOSITIVOS D ON D.ID_SETOR=S.ID WHERE S.DESCRICAO=' + #39 + cb_setor.Text + #39;
    dmbanco.set_dispositivos.Open;
 	end;
end;

procedure Tfrmoperacao.cb_setorClick(Sender: TObject);
begin
  if cb_setor.Text <> '' then
  begin
    dmbanco.set_dispositivos.Close;
    dmbanco.set_dispositivos.SQL.Clear;
    dmbanco.set_dispositivos.SQL.Text := 'SELECT D.ID_SETOR, D.NOME, S.ID, S.DESCRICAO FROM SETORES S INNER JOIN DISPOSITIVOS D ON D.ID_SETOR=S.ID WHERE S.DESCRICAO=' + #39 + cb_setor.Text + #39;
    dmbanco.set_dispositivos.Open;
 	end;
end;

procedure Tfrmoperacao.cb_setorDragDrop(Sender, Source: TObject; X,
  Y: Integer);
begin
  if cb_setor.Text <> '' then
  begin
    dmbanco.set_dispositivos.Close;
    dmbanco.set_dispositivos.SQL.Clear;
    dmbanco.set_dispositivos.SQL.Text := 'SELECT D.ID_SETOR, D.NOME, S.ID, S.DESCRICAO FROM SETORES S INNER JOIN DISPOSITIVOS D ON D.ID_SETOR=S.ID WHERE S.DESCRICAO=' + #39 + cb_setor.Text + #39;
    dmbanco.set_dispositivos.Open;
 	end;
end;

end.
